package day4;

public class 斐波那契数列 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		// 注意 hasNext 和 hasNextLine 的区别
		while (in.hasNextInt()) { // 注意 while 处理多个 case
			int n = in.nextInt();
			if (n == 1) {
				System.out.println(0);
			} 
			else {
				int p=0,q=1,r=1;
				while (r < n) {
					int tmp=q+r;
					p=q;
					q=r;
					r=tmp;
				}
				if(r==n){
					System.out.println(0);
				}
				else{
					System.out.println(Math.min(r-n,n-q));
				}
			}
		}
	}
}
